<!--
  停车场表编辑页面
  User: YanZengBao
  Date: 2020-02-19
-->
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<!-- BEGIN FORM-->
<div class="portlet light">
    <div class="portlet-title">
        <div class="caption">
            <span class="caption-subject font-red-sunglo bold uppercase">停车场表编辑</span>
            <span class="caption-helper">编辑一条停车场表数据</span>
        </div>
    </div>
    <div class="portlet-body form">
        <!-- BEGIN FORM-->
        <form action="#" class="form-horizontal" id="edit-module">
            <div class="form-body">

                <!--  字段信息-->
                <div class="form-group hide">
                    <label class="col-md-3 control-label"></label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" disabled class="form-control" required name="id"
                                       th:value="${data['id']}" placeholder="">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 编号(不允许重复) 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">停车场编号</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" readonly class="form-control" required name="number"
                                       th:value="${data['number']}" placeholder="编号(不允许重复)">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 停车场名称 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">停车场名称</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" readonly class="form-control" required name="name"
                                       th:value="${data['name']}" placeholder="停车场名称">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 停车场类型（0-封闭停车场 1-。。。） 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">停车场类型</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select required name="parkType" disabled class="form-control">
                                    <option th:selected="${data['parkType'] == 1}" value="1">路侧停车场</option>
                                    <option th:selected="${data['parkType'] == 0}" value="0">封闭停车场</option>
                                </select>
                                <!-- <input type="number" readonly class="form-control" required  name="parkType" th:value="${data[''] == 0} ? '':''" placeholder="停车场类型（0-封闭停车场 1-。。。）">-->
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 省 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">省</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" readonly class="form-control" required th:value="${data['province']}"
                                       placeholder="省">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 市 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">市</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" readonly class="form-control" required th:value="${data['city']}"
                                       placeholder="市">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 区县 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">区县</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" readonly class="form-control" required th:value="${data['county']}"
                                       placeholder="区县">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 详细地址 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">详细地址</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" readonly class="form-control" maxlength="255" required name="address"
                                       th:value="${data['address']}" placeholder="详细地址">
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 详细地址 地图选择-->
                <div class="form-group">
                    <label class="col-md-3 control-label">选择经纬度</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>

                                <input th:data-lng="${data['longitude']}" th:data-lat="${data['latitude']}" th:data-city-name="${data['city']}" id="lnglat" onclick="openMap(this);" type="text" readonly class="form-control"
                                       th:value="${data['longitude'] == null ? '' : data['longitude'] +','+ data['latitude']}" placeholder="经纬度">
                                <input type="hidden" value="" class="form-control" readonly name="longitude" id="longitude"placeholder="经度">
                                <input type="hidden" value="" class="form-control"  readonly name="latitude" id="latitude" placeholder="纬度">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 是否对临时车开放(0:暂不开放 1:开放) 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">是否对临时车开放</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select required readonly name="openStatus" class="form-control">
                                    <option th:selected="${data['openStatus'] == 1}" value="1">开放</option>
                                    <option th:selected="${data['openStatus'] == 0}" value="0">封闭</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 是否收费（0：不收费 1:收费） 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">是否收费</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>

                                <select required readonly name="feeStatus" class="form-control">
                                    <option th:selected="${data['feeStatus'] == 1}" value="1">收费</option>
                                    <option th:selected="${data['feeStatus'] == 0}" value="0">免费</option>
                                </select>
                                <!--<input type="number" class="form-control" required  name="feeStatus" th:value="${data['']}" placeholder="是否收费（0：不收费 1:收费）">-->
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 是否允许超位入场（0-允许 1-禁止） 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">是否允许超位入场</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select required readonly name="overParkinglotStatus" class="form-control">
                                    <option th:selected="${data['overParkinglotStatus'] == 1}" value="1">禁止</option>
                                    <option th:selected="${data['overParkinglotStatus'] == 0}" value="0">允许</option>
                                </select>
                                <!--<input type="number" class="form-control" required  name="" th:value="${data['overParkinglotStatus']}" placeholder="是否允许超位入场（0-允许 1-禁止）">-->
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 停车场图片 字段信息-->
                <!-- <div class="form-group">
                     <label class="col-md-3 control-label">停车场图片</label>
                     <div class="col-md-4">
                         <div class="input-inline ">
                             <div class="input-group">
                                 <span class="input-group-addon">
                                     <i class="fa fa-edit"></i>
                                 </span>
                                 <input type="text" class="form-control" required minlength="2" name="imgUrl" th:value="${data['imgUrl']}" placeholder="停车场图片">
                             </div>
                         </div>
                     </div>
                 </div>-->

                <!-- 车位总数 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">车位总数</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="number" class="form-control" readonly maxlength="5" id="parkinglotTotal" required
                                       name="parkinglotTotal" th:value="${data['parkinglotTotal']}" placeholder="车位总数">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 剩余车位数 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">剩余车位数</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="number" class="form-control" readonly maxlength="5" id="parkinglotSurplus" required
                                       name="parkinglotSurplus" th:value="${data['parkinglotSurplus']}"
                                       placeholder="剩余车位数">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 开放时间起 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">开放时间起</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" readonly required minlength="2"
                                       name="openStartTime" th:value="${data['openStartTime']}" placeholder="开放时间起">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 开放时间止 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">开放时间止</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" readonly required minlength="2"
                                       name="openStopTime" th:value="${data['openStopTime']}" placeholder="开放时间止">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 备注 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">备注</label>
                    <div class="col-md-4">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" readonly maxlength="255" name="intro"
                                       th:value="${data['intro']}" placeholder="备注">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-actions">
                <div class="row">
                    <div class="col-md-6">
                        <div class="row">
                            <div class="col-md-offset-3 col-md-9">
                                <button type="button" class="btn green" onclick="edit();">保存</button>
                                <button type="button" class="btn default" onclick="layer.close(layer_editModule);">取消
                                </button>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6"></div>
                </div>
            </div>
        </form>
        <!-- END FORM-->
    </div>
</div>

<script>

    $(function () {
        //初始化页面
        initPage();
    });

    $(".datetimePicker").datetimepicker({
        format: 'hh:ii:00',
        language: "zh-CN",
        startView: 1,
        minView: 0,
        forceParse: true,
        minuteStep: 10,
        autoclose: true,
    });

    function edit() {
        let param = tools.formParams("edit-module");
        if (tools.valid("edit-module")) {
            var parkinglotTotal = $("#parkinglotTotal").val();
            var parkinglotSurplus = $("#parkinglotSurplus").val();
            console.log("parkinglotTotal：" + parkinglotTotal + "parkinglotSurplus剩余车位数：" +  parkinglotSurplus);
            if (parseInt(parkinglotSurplus) > parseInt(parkinglotTotal)) {
                layer.msg("剩余车位数不能大于总车位数！", {icon: 0, time: 2000});
                return;
            } else {
                tools.post("/park/update", param, function (data) {
                    if (data.success) {
                        layer.msg(data.message, {icon: 1, time: 1000}, function () {
                            //刷新列表页面
                            toPage(null);
                            //关闭弹窗
                            layer.close(layer_editModule);
                        });
                    } else {
                        tools.errorTip(data.code, data.message);
                    }
                });
            }
        }
    }

    function openMap(obj) {

        let cityName = $(obj).data("cityName");
        let lng = $(obj).data("lng");
        let lat = $(obj).data("lat");

        window.layer_mapModule = layer.open({
            id:"mapModule",
            type: 2,
            title:"选择地图",
            area:['900px','600px'],
            content: "/park/chooseAddress?cityName="+cityName+"&longitude="+lng+"&latitude="+lat,
            anim:1,
            shadeClose:false,
            btn:["确定","取消"],
            yes:function(){

                $("#lnglat").val($("#longitude").val()+","+$("#latitude").val());
                layer.close(layer_mapModule);
            },
            btn2:function(){},
            cancel: function(){}
        });

    }

</script>
</html>